package stud.mpgame.network.util;

import flash.utils.IDataInput;
import flash.utils.IDataOutput;

import stud.mpgame.network.Message;
import stud.mpgame.network.MessageDescription;
import stud.mpgame.network.UserObject;

/**
 * ...
 * @author Timofeev
 */

class ResponseUserObject extends UserObject {

    private var messageDescription:MessageDescription;
    private var serialNumber:Int;
    private var sentTime:Int;
    private var receivedTime:Int;
    
    public function new(messageDescription:MessageDescription, serialNumber:Int, sentTime:Int, receivedTime:Int) {
        super();
        this.messageDescription = messageDescription;
        this.serialNumber = serialNumber;
        this.sentTime = sentTime;
        this.receivedTime = receivedTime;
    }

    public function getReceivedTime():Int {
        return receivedTime;
    }

    public function getSentTime():Int {
        return sentTime;
    }

    public function getSerialNumber():Int {
        return serialNumber;
    }

    public function getMessageDescription():MessageDescription {
        return messageDescription;
    }

    public override function readExternal(input:IDataInput, message:Message):Void {
        var messageDescriptionID:Int = input.readInt();        
        this.messageDescription = MessageDescription.getMessageDescriptionByID(messageDescriptionID);
        this.serialNumber = input.readInt();
        this.sentTime = input.readInt();
        this.receivedTime = input.readInt();        
    }
    
    public override function writeExternal(output:IDataOutput, message:Message):Void {
        output.writeInt(messageDescription.getID());
        output.writeInt(serialNumber);
        output.writeInt(sentTime);
        output.writeInt(receivedTime);
    }
    
}